<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    use Notifiable, HasRoles, HasApiTokens;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'avatar'
    ];

    protected $guard_name = 'admin';

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    protected $appends = ['avatar'];

    public static function boot()
    {
        parent::boot();
        static::creating(function ($mode) {
            $mode->password = bcrypt(trim(request()->get('password')));
        });
    }


    /**
     * 获取头像属性
     * @return string
     */
    public function getAvatarAttribute()
    {
        return "https://cdn.learnku.com/uploads/avatars/30083_1539912514.jpg!/both/100x100";
    }
    public function getEmailVerifiedAtAttribute($value)
    {
        return $value?"已验证":"待验证";
    }

}
